%div.role-row.role-row--merchandise
  .item-block-role.item-block-role--merchandise
    - if f.object.role == 'merchandise'
    :ruby
      options = {
        label: :merchandise.tl,
        source: {scope: :purchaseables_stockables_or_depreciables},
        input_html: {
          class: "parcel-item-variant",
          data: {
            product_of_delivery_item: {
              url: backend_product_nature_variant_path("RECORD_ID", format: :json),
              scope: 'target'
            },
            required: true,
          }
        }
      }
    = f.referenced_association(:variant, **options)
      - display = ""
      - display = "display: none;" unless variant.identifiable?.or_else(false)
    .annotation-logo
      - if f.object.annotation.blank?
        = link_to("#", data: { annotate: ".annotate", use_closest: "tbody" }, title: :add_annotation.tl) do
          %i.annotation-field



  .item-block-delivery-mode{style: "display: flex"}
    = f.label :delivery_mode.tl
    %div.delivery-mode__input
      = f.input :delivery_mode, as: :radio_buttons, collection: f.object.class.delivery_mode.values.sort_by(&:l) - ['none'],label: false, label_method: :l, input_html: { class: 'item-delivery-mode', data: {  input_to_show: '.transporter-delivery-mode', with_value: "transporter", use_as_value: '.transporter-delivery-mode > input.hidden' } }
      .transporter-delivery-mode.hidden.delivery-item
        = f.referenced_association :transporter, source: :transporters, label: false, new: {transporter: 1}, input_html: { class: 'transporter-delivery-mode', data: { product_of_delivery_item: { url: backend_entity_path("RECORD_ID", format: :json) } } }
        - full_name = f.object.transporter.full_name if f.object.transporter
        %input.hidden{data: { 'when-item': 'full_name', 'when-set-value': 'RECORD_VALUE' }, value: full_name }
.unitary-variant-fields{style: display, data: {"when-item": "identifiable", "when-display-value": 'true', "when-scope": 'target'}}
  = f.input :product_name, required: true do
    = f.input_field :product_name, data: { required: true }
  = f.input :product_identification_number, required: true do
    = f.input_field :product_identification_number, data: { required: true }
  = f.input :product_work_number do
    = f.input_field :product_work_number
.annotation-section
  .annotation-field
    - attrs = {}
    - attrs[:style] = "display: none" if f.object.annotation.blank?
    .annotate{attrs}= f.input(:annotation, wrapper: :nested, input_html: { class: "annotation" })

%div#add-storing.storing-row.storing-row--merchandise
  .item-block__storing.control-group.storing__content{data: {association_insertion_minimum: 1}}
    - f.object.storings.new if f.object.storings.size == 0
    = f.simple_fields_for :storings, f.object.storings do |storing|
      = render 'storing_fields', f: storing
    .div.storing__footer
      = link_to_add_association :add_storing.tl, f, :storings, partial: 'storing_fields', class: "link-add-storing", data: { :'association-insertion-method' => :before }
      %label.total-labels
        %span.total= :total.tl
        %span.total-quantity{ data: { calculate: "sum", use: ".storing-fields:not(.removed-nested-fields) .storing-quantity", use_closest: ".nested-item-form", calculate_round: 2 } }= 0.0
        %span{data: { 'when-item': 'unit_name', 'when-set-value': 'RECORD_VALUE', 'when-scope': 'target'}}
          = variant.unit_name.or_else('unité(s)')

      = f.input :merge_stock

      %div.current-stock
        .merchandise-total-current-stock
          %span.stock-label= :current_stock.tl
          %span.stock-value= variant.current_stock.or_else(0)
          %span.stock-unit= variant.unit_name.or_else("")

        .merchandise-total-stock-after-reception
          %span.stock-label= :stock_after_order.tl
          %span.stock-value= f.object.decorate.merchandise_stock_after_reception(variant.current_stock.or_else(0))
          %span.stock-unit= f.object.decorate.merchandise_stock_unit(variant.unit_name.or_else(""))


